package com.caiheng.api.service.estate.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.caiheng.api.dao.estate.EstateMapper;
import com.caiheng.api.entity.estate.Estate;
import com.caiheng.api.service.estate.EstateService;
import com.caiheng.api.service.base.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 小区列Service业务层处理
 *
 * @author ruoyi
 * @date 2021-08-18
 */
@Service
public class EstateServiceImpl extends BaseServiceImpl<EstateMapper, Estate> implements EstateService {

    @Resource
    private EstateMapper estateMapper;


    @Override
    public List<Map<String, Object>> getEstateListByPinyinGroup(String keyword) {
        List<Map<String, Object>> list = new ArrayList<>();
        String[] characters = new String[]{ "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z" };
        for (String c : characters){
            QueryWrapper<Estate> qw = new QueryWrapper<>();
            qw.eq("name_character",c);
            qw.eq("state",0);
            if(StrUtil.isNotEmpty(keyword)){
                qw.like("estate_name",keyword);
            }
            List<Estate> estates = estateMapper.selectList(qw);
            if(CollUtil.isNotEmpty(estates)){
                Map<String, Object> map = new HashMap<>();
                map.put("key",c);
                map.put("value",estates);
                list.add(map);
            }
        }
        return list;
    }

    @Override
    public List<Map<String, Object>> getEstateListByUserBand(int userId) {
        List<Map<String, Object>> list = new ArrayList<>();
        String[] characters = new String[]{ "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z" };
        for (String c : characters){
            Map<String,Object> mapParam = new HashMap<>();
            mapParam.put("userId", userId);
            mapParam.put("nameCharacter",c);
            List<Estate> estates = estateMapper.getEstateListByUserBand(mapParam);
            if(CollUtil.isNotEmpty(estates)){
                Map<String, Object> map = new HashMap<>();
                map.put("key",c);
                map.put("value",estates);
                list.add(map);
            }
        }
        return list;
    }

    @Override
    public List<Estate> getEstateListByAdminId(int userId, int userType) {
        Map<String,Object> map = new HashMap<>();
        map.put("userId",userId);
        map.put("userType",userType);//客服
        List<Estate> list = estateMapper.selectAdminList(map);
        return list;
    }
}
